package com.woniuxy.enjoylife.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.enjoylife.entity.Log;
import com.woniuxy.enjoylife.entity.dto.SelectLogDto;
import com.woniuxy.enjoylife.mapper.LogMapper;
import com.woniuxy.enjoylife.utils.PageResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/log")
public class LogController {
    @Resource
    private LogMapper logMapper;

    @RequestMapping("/select")
    public PageResult<Log> selectLog(SelectLogDto log) {
        if (null != log.getContent()) {
            log.setContent("%" + log.getContent() + "%");
        }

        PageResult<Log> result = new PageResult<>();
        Page<Log> page = PageHelper.startPage(log.getPage(), log.getSize());
        List<Log> logs = logMapper.selectLog(log);

        result.setPageSize(log.getSize()).setCurrentPage(log.getPage()).setTotalPage(page.getPageNum()).setTotal(page.getTotal()).setData(logs);

        return result;
    }
}
